//
//  AllocateLibraryViewController.m
//  ShoppingExperience
//
//  Created by LiYinDi on 15-6-2.
//  Copyright (c) 2015年 RuiBen. All rights reserved.
//

#import "AllocateLibraryViewController.h"
#import "AllocateLibraryTableViewCell.h"
#import "SearchProductTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "UpCounterDetailTableViewCell.h"
#import "GuideListTableViewCell.h"
#import "EGORefreshTableHeaderView.h"
#import "CommonScanViewController.h"
#import "FilterViewController.h"
#import "CommonProductDetailViewController.h"
@interface AllocateLibraryViewController ()<EGORefreshTableHeaderDelegate,CommonScanDelegate,FilterViewControllerDelegate,CommonProductDetailDelegate>
{
    CommonProductDetailViewController *commonProductDetailVC;
    FilterViewController *filterVC;
    CommonScanViewController *commonScanVC;
    EGORefreshTableHeaderView *_refreshHeaderView;
    BOOL _reloading;
    
    NSUInteger _PageIndex;
    NSUInteger _TotalCount;
    NSUInteger _TotalPage;

    NSUInteger _productPageIndex;
    NSUInteger _productTotalCount;
    NSUInteger _productTotalPage;
    
    NSMutableArray *allcateProductNameArray;
    NSMutableArray *allcateNumArray;
    NSMutableArray *allcateWeightArray;
    NSMutableArray *allcateNumberArray;
    NSMutableArray *allcateGuideNameArray;
    NSMutableArray *allcateDateArray;
    NSMutableArray *allcateStatusArray;
    NSMutableArray *allcatePriceArray;
    NSMutableArray *allcateDocStatusArray;
    
       
    NSUInteger searchProductCellTag;
    BOOL guideIsOpen;
    BOOL allocateIsOpen;
    
    NSMutableArray *selectedProductImageArray;
    NSMutableArray *selectedProductWeightArray;
    NSMutableArray *selectedProductPriceArray;
    NSMutableArray *selectedProductNameArray;
    NSMutableArray *selectedProductCodeArray;
    NSMutableArray *selectedProductWhereArray;
    
    NSMutableArray *guideNameArray;
    NSMutableArray *guideCodeArray;
    NSString *guideCodeStr;
    NSString *allocateCodeStr;
    NSMutableArray *allocateNameArray;
    NSMutableArray *allocateCodeArray;

    
    NSMutableArray *detailUrlArray;
    NSMutableArray *detailProductNameArray;
    NSMutableArray *detailProductCodeArray;
    NSMutableArray *detailLinePriceArray;
    NSMutableArray *detailWeightArray;
    NSMutableArray *detailAddressArray;
    NSMutableArray *detailAttributesArray;
    
    NSString *guideOrAllocateStr;
    UITextField *inputTextField;
    
    NSMutableArray *filterTypeCodeArray ;
    NSMutableArray *inputFilterCodeArray;
    NSMutableArray *inputMinResultFilterNameArray;
    NSMutableArray *inputMaxResultFilterNameArray;
    NSMutableArray *selectFilterCodeArray;
    NSMutableArray *selectFilterNameArray;
    NSMutableArray *selectCustomTimeArray ;
    NSMutableArray *customTimeFilterTypeCodeArray ;
    NSString *startTimeStr;
    NSString *endTimeStr;
   
}
- (void)reloadTableViewDataSource;
- (void)doneLoadingTableViewData;
@end

@implementation AllocateLibraryViewController
-(void)viewWillAppear:(BOOL)animated
{
     if ([_isLoad isEqualToString:@"N"]) {
    if (commonProductDetailVC.view!=nil) {
             
             [commonProductDetailVC removeFromParentViewController];
             [commonProductDetailVC.view removeFromSuperview];
             
         }

    if (commonScanVC.view!=nil) {
        if (commonScanVC.timer!=nil) {
            [commonScanVC.timer invalidate];
            commonScanVC.timer=nil;
        }
        if (commonScanVC.captureSession!=nil) {
            
            
            [commonScanVC.captureSession stopRunning];
            commonScanVC.captureSession = nil;
        }
        if (commonScanVC.videoPreviewLayer !=nil) {
            
            
            [commonScanVC.videoPreviewLayer removeFromSuperlayer];
        }
        

        [commonScanVC.view removeFromSuperview];
        [commonScanVC removeFromParentViewController];
        
    }
    if (filterVC.view!=nil) {
        
        [filterVC removeFromParentViewController];
        [filterVC.view removeFromSuperview];
        
    }

    [self initUpCounterViewContainer];
    [self initDetailViewContainer];
    [self initAllocateList];
    [self initOrderFilterView];
    _productPageIndex=0;
    [self loadProductNextPage:_productPageIndex];
     }
}
-(void)initOrderFilterView
{
    inputFilterCodeArray=[NSMutableArray array];
    inputMinResultFilterNameArray=[NSMutableArray array];
    inputMaxResultFilterNameArray=[NSMutableArray array];
    filterTypeCodeArray=[NSMutableArray array];
    customTimeFilterTypeCodeArray=[NSMutableArray array];
    selectFilterCodeArray=[NSMutableArray array];
    selectFilterNameArray=[NSMutableArray array];
    selectCustomTimeArray=[NSMutableArray array];
    
    startTimeStr=@"";
    endTimeStr=@"";
    
    [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:80.0f/255.0f green:80.0f/255.0f blue:80.0f/255.0f alpha:1.0f]];
    [_orderFilterImage setImage:[UIImage imageNamed:@"shaixuandingdan_.png"]];
    // [_orderFilterViewContainer bringSubviewToFront:_resetFilterBtn];
    
    _orderFilterBtn.layer.borderColor=[[UIColor colorWithRed:220.0f/255.0f green:220.0f/255.0f blue:220.0f/255.0f alpha:1] CGColor];
    _orderFilterBtn.layer.borderWidth= 1.0f;
    _orderFilterBtn.layer.cornerRadius=4;
    
    [_orderFilterBtn addTarget:self action:@selector(orderFilterBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    

    
}
-(void)orderFilterBtnClick
{
    if (filterVC.view!=nil) {
        
        [filterVC removeFromParentViewController];
        [filterVC.view removeFromSuperview];
        
    }
    filterVC=[[FilterViewController alloc] init];
    filterVC.delegate=self;
    filterVC.docTypeStr=@"DTrans";
    filterVC.selectCustomTimeArray=[NSMutableArray arrayWithArray:selectCustomTimeArray];
    filterVC.startTimeStr=startTimeStr;
    filterVC.endTimeStr=endTimeStr;
    // NSLog(@"selectFilterNameArray=22222======%@",selectFilterNameArray);
    filterVC.selectFilterNameArray=[NSMutableArray arrayWithArray:selectFilterNameArray];
    filterVC.view.frame = CGRectMake(0,
                                     0,
                                     self.view.bounds.size.width,
                                     self.view.bounds.size.height);
    
    [self addChildViewController:filterVC];
    [self.view addSubview:filterVC.view];
}
-(void)confirmFilterBtnClick:(NSMutableArray *)commonFilterTypeCodeArray commonSelectFilterCodeArray:(NSMutableArray *)commonSelectFilterCodeArray commonInputFilterCodeArray:(NSMutableArray *)commonInputFilterCodeArray commonInputMinResultFilterNameArray:(NSMutableArray *)commonInputMinResultFilterNameArray commonInputMaxResultFilterNameArray:(NSMutableArray *)commonInputMaxResultFilterNameArray commonCustomTimeFilterTypeCodeArray:(NSMutableArray *)commonCustomTimeFilterTypeCodeArray commonSelectCustomTimeArray:(NSMutableArray *)commonSelectCustomTimeArray commonSelectFilterNameArray:(NSMutableArray *)commonSelectFilterNameArray  commonStartTimeStr:(NSString *)commonStartTimeStr commonEndTimeStr:(NSString *)commonEndTimeStr isDefault:(NSString *)isDefault
{
    
    if ([isDefault isEqualToString:@"Y"]) {
        //  NSLog(@"_isDefault0000===%@",isDefault);
        [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:80.0f/255.0f green:80.0f/255.0f blue:80.0f/255.0f alpha:1.0f]];
        [_orderFilterImage setImage:[UIImage imageNamed:@"shaixuandingdan_.png"]];
    }
    else{
        // NSLog(@"_isDefault1111===%@",isDefault);
        [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:203.0f/255.0f green:164.0f/255.0f blue:67.0f/255.0f alpha:1.0f]];
        [_orderFilterImage setImage:[UIImage imageNamed:@"yishaixuan_.png"]];
    }
    
    filterTypeCodeArray=commonFilterTypeCodeArray;
    selectFilterCodeArray=commonSelectFilterCodeArray;
    inputFilterCodeArray=commonInputFilterCodeArray;
    inputMinResultFilterNameArray=commonInputMinResultFilterNameArray;
    inputMaxResultFilterNameArray=commonInputMaxResultFilterNameArray;
    customTimeFilterTypeCodeArray=commonCustomTimeFilterTypeCodeArray;
    selectCustomTimeArray=commonSelectCustomTimeArray;
    selectFilterNameArray=commonSelectFilterNameArray;
    
    startTimeStr=commonStartTimeStr;
    endTimeStr=commonEndTimeStr;
    
    [allcateNumArray removeAllObjects];
    [allcatePriceArray removeAllObjects];
    [allcateGuideNameArray removeAllObjects];
    [allcateDateArray removeAllObjects];
    [allcateStatusArray removeAllObjects];
    [allcateDocStatusArray removeAllObjects];
    [allcatePriceArray removeAllObjects];
    [allcateProductNameArray removeAllObjects];
    [allcateNumberArray removeAllObjects];
    [allcateWeightArray removeAllObjects];

    
    _productPageIndex=0;
    [self loadProductNextPage:_productPageIndex];
}

-(void)initDetailViewContainer
{
    detailUrlArray=[NSMutableArray array];
    detailProductNameArray=[NSMutableArray array];
    detailLinePriceArray=[NSMutableArray array];
    detailWeightArray=[NSMutableArray array];
    detailProductCodeArray=[NSMutableArray array];
    detailAddressArray=[NSMutableArray array];
    detailAttributesArray=[NSMutableArray array];
    
    [_addAllocateDetailAlphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
    [_addAllocateDetailAlphaView addTarget:self action:@selector(upCounterDetailAlphaViewClick) forControlEvents:UIControlEventTouchUpInside];
    
    CGRect viewFrame=_addAllocateDetailViewContainer.frame;
    viewFrame.origin.y=768;
    _addAllocateDetailViewContainer.frame=viewFrame;
    
}
-(void)initUpCounterViewContainer
{
    [_resultScrollview setContentOffset:CGPointMake(0, 0)];
    allocateIsOpen=NO;
    guideIsOpen=NO;
    guideCodeStr=@"";
    guideOrAllocateStr=@"";
    allocateCodeStr=@"";
    
    selectedProductImageArray=[NSMutableArray array];
    selectedProductWeightArray=[NSMutableArray array];
    selectedProductPriceArray=[NSMutableArray array];
    selectedProductNameArray=[NSMutableArray array];
    selectedProductCodeArray=[NSMutableArray array];
    selectedProductWhereArray=[NSMutableArray array];
    
    guideNameArray=[NSMutableArray array];
    guideCodeArray=[NSMutableArray array];
    allocateNameArray=[NSMutableArray array];
    allocateCodeArray=[NSMutableArray array];

    _resultTextView.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1] CGColor];
    _resultTextView.layer.borderWidth= 1.0f;
    _resultTextView.layer.cornerRadius=3;
    
    CGRect viewFrame=_addAllocateViewContainer.frame;
    viewFrame.origin.y=768;
    _addAllocateViewContainer.frame=viewFrame;
    
  
    
    [_addAllocateResultAlphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
    [_addAllocateResultAlphaView addTarget:self action:@selector(upCounterResultAlphaViewClick) forControlEvents:UIControlEventTouchUpInside];
    
    _resultGuideListBtn.tag=60;
    [_resultGuideListBtn addTarget:self action:@selector(selectGuideBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    _resultAllocateListBtn.tag=60;
    [_resultAllocateListBtn addTarget:self action:@selector(selectAllocateBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
//    CGRect viewFrame1=_upCounterViewContainer.frame;
//    viewFrame1.origin.y=768;
//    _upCounterViewContainer.frame=viewFrame1;
    CGRect frameb=_addAllocateResultView.frame;
    frameb.origin.y=0;
    [_addAllocateResultView setFrame:frameb];
  
    
    
}
-(void)upCounterDetailAlphaViewClick
{
    [_searchTextField resignFirstResponder];
    
    [_resultTextField resignFirstResponder];
    [_resultTextView resignFirstResponder];
    [_detailScrollview setContentOffset:CGPointMake(0, 0)];
    [UIView animateWithDuration:0.5 animations:^{
        
        
        CGRect frame=_addAllocateDetailViewContainer.frame;
        
        frame.origin.y=768;
        [_addAllocateDetailViewContainer setFrame:frame];
        
    } completion:^(BOOL finished){
        
    }];
    
}
-(void)selectGuideBtnClick:(UIButton *)sender
{
    _resultHouseListViewContainer.hidden=YES;
    
        CGRect frame=_resultHouseListViewContainer.frame;
        
        frame.size.height=1;
        [_resultHouseListViewContainer setFrame:frame];

        guideOrAllocateStr=@"GUIDE";
        
        if (guideIsOpen) {
            _resultGuideListViewContainer.hidden=YES;
                       [UIView animateWithDuration:0.5 animations:^{
                
//                UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
//                [_resultGuideListArrowImage setImage:closeImage];
                CGRect frame=_resultGuideListViewContainer.frame;
                
                frame.size.height=1;
                [_resultGuideListViewContainer setFrame:frame];
                
            } completion:^(BOOL finished){
                guideIsOpen=NO;
            }];
            
        }
        else
        {
            [self requestGuideList];
            _resultGuideListViewContainer.hidden=NO;
            CGRect frame1=_resultGuideListViewContainer.frame;
            frame1.origin.y=111;
            [_resultGuideListViewContainer setFrame:frame1];

            [UIView animateWithDuration:0.5 animations:^{
//                UIImage *closeImage=[UIImage imageNamed:@"jiantou_upward.png"];
//                
//                
//                [_resultGuideListArrowImage setImage:closeImage];
                CGRect frame=_resultGuideListViewContainer.frame;
                
                frame.size.height=657;
                [_resultGuideListViewContainer setFrame:frame];
                
            } completion:^(BOOL finished){
                guideIsOpen=YES;
            }];
            
        }
   // }
}
-(void)selectAllocateBtnClick:(UIButton *)sender
{
    _resultGuideListViewContainer.hidden=YES;
//    UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
//    [_resultGuideListArrowImage setImage:closeImage];
    CGRect frame=_resultGuideListViewContainer.frame;
    
    frame.size.height=1;
    [_resultGuideListViewContainer setFrame:frame];

        guideOrAllocateStr=@"ALLOCATE";
        
        if (allocateIsOpen) {
            _resultHouseListViewContainer.hidden=YES;
            [UIView animateWithDuration:0.5 animations:^{
                
               
                CGRect frame=_resultHouseListViewContainer.frame;
                
                frame.size.height=1;
                [_resultHouseListViewContainer setFrame:frame];
                
            } completion:^(BOOL finished){
                allocateIsOpen=NO;
            }];
            
        }
        else
        {
            [self requestAllocateList];
            _resultHouseListViewContainer.hidden=NO;
            CGRect frame1=_resultHouseListViewContainer.frame;
            frame1.origin.y=161;
            [_resultHouseListViewContainer setFrame:frame1];

            [UIView animateWithDuration:0.5 animations:^{
                
                CGRect frame=_resultHouseListViewContainer.frame;
                
                frame.size.height=657;
                [_resultHouseListViewContainer setFrame:frame];
                
            } completion:^(BOOL finished){
                allocateIsOpen=YES;
            }];
            
        }
   

}
-(void)requestGuideList
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [HttpRequest requestData:@"Guide/GuideList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    [guideCodeArray removeAllObjects];
                    [guideNameArray removeAllObjects];
                    NSMutableArray *mGuidesArray=[severDataDict.dataDict objectForKey:@"DataLine"];
                    for (int i=0; i<mGuidesArray.count; i++) {
                        [guideCodeArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"UserCode"]];
                        [guideNameArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"UserName"]];
                    }
                    // NSLog(@"guideCodeArray==%@",guideCodeArray);
                    //
                    
                    [_resultGuideListTableView reloadData];
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}
-(void)requestAllocateList
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:@"T" forKey:@"WhsType"];
        [HttpRequest requestData:@"StoreManager/WhsList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                   // NSLog(@"333333===%@",severDataDict.dataDict);
                    
                    [allocateCodeArray removeAllObjects];
                    [allocateNameArray removeAllObjects];
                    NSMutableArray *mAllocateArray=[severDataDict.dataDict objectForKey:@"DataLine"];
                    for (int i=0; i<mAllocateArray.count; i++) {
                        [allocateCodeArray addObject:[[mAllocateArray objectAtIndex:i] objectForKey:@"WhsCode"]];
                        [allocateNameArray addObject:[[mAllocateArray objectAtIndex:i] objectForKey:@"WhsName"]];
                    }
                    // NSLog(@"guideCodeArray==%@",guideCodeArray);
                    //
                    
                    [_resultHouseListTableView reloadData];
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}

-(void)upCounterResultAlphaViewClick
{
    [_searchTextField resignFirstResponder];
   
    [_resultTextField resignFirstResponder];
    [_resultTextView resignFirstResponder];
    [_resultScrollview setContentOffset:CGPointMake(0, 0)];
       [UIView animateWithDuration:0.5f animations:^
     {
         CGRect viewFrame=_addAllocateViewContainer.frame;
         viewFrame.origin.y=768;
         _addAllocateViewContainer.frame=viewFrame;
        

         CGRect viewFrame0=_addAllocateResultView.frame;
         viewFrame0.origin.y=0;
         _addAllocateResultView.frame=viewFrame0;
     }completion:^(BOOL finished) {
         
     }];
    
}

-(void)initAllocateList
{
    _searchTextField.text=@"";
//    _addAllocateBtn.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1] CGColor];
//    _addAllocateBtn.layer.borderWidth= 1.0f;
//    _addAllocateBtn.layer.cornerRadius=3;
    [_addAllocateBtn addTarget:self action:@selector(addAllocateBtnClick) forControlEvents:UIControlEventTouchUpInside];

    allcateProductNameArray=[NSMutableArray array];
    allcateNumArray=[NSMutableArray array];
    allcateWeightArray=[NSMutableArray array];
    allcateNumberArray=[NSMutableArray array];
    allcateGuideNameArray=[NSMutableArray array];
    allcateDateArray=[NSMutableArray array];
    allcateStatusArray=[NSMutableArray array];
    allcateDocStatusArray =[NSMutableArray array];
    allcatePriceArray=[NSMutableArray array];
}
-(void) loadProductNextPage:(NSUInteger)oldPageNum {
    if(oldPageNum!=0 && _productTotalCount<=allcateNumArray.count)
        return;
    if(oldPageNum == 0){
        [allcateNumArray removeAllObjects];
        [_allocateTableView reloadData];
    }
    _productPageIndex=oldPageNum+1;
    [self requestAllocateList: _productPageIndex pageSize:6];
}
-(IBAction)addScanBtnClick :(id)sender
{
    [_resultTextField resignFirstResponder];
    if (commonScanVC.view!=nil) {
        
        [commonScanVC removeFromParentViewController];
        [commonScanVC.view removeFromSuperview];
        
    }
    commonScanVC=[[CommonScanViewController alloc] init];
    commonScanVC.delegate=self;
    
    commonScanVC.view.frame = CGRectMake(0,
                                         0,
                                         self.view.bounds.size.width,
                                         self.view.bounds.size.height);
    
    [self addChildViewController:commonScanVC];
    [self.view addSubview:commonScanVC.view];
    
}
-(void)CommonScanResult:(NSString *)codeStr
{
    //NSLog(@"codeStr=====%@",codeStr);
    if (commonScanVC.view!=nil) {
        //   NSLog(@"dddddddd");
        [commonScanVC removeFromParentViewController];
        [commonScanVC.view removeFromSuperview];
        
    }
    [self findProductList:codeStr];
    
}

-(void)addAllocateBtnClick
{
   _resultTextField .text=@"";
    [_searchTextField resignFirstResponder];
    _resultGuideNameLabel.text=[Global getGuideNameStr];
    guideCodeStr=[Global getGuideCodeStr];
    allocateCodeStr=@"";
    _resultAllocateNameLabel.text=@"";
    _resultNoteView.hidden=NO;
   
     _totalMoneyLabel.text=[NSString stringWithFormat:@"共0件,0.00g"];
    
   
    
    [selectedProductImageArray removeAllObjects];
     [selectedProductWeightArray removeAllObjects];
     [selectedProductWhereArray removeAllObjects];
    [selectedProductPriceArray removeAllObjects];
     [selectedProductNameArray removeAllObjects];
    [selectedProductCodeArray removeAllObjects];
    [_resultTableView reloadData];
    [UIView animateWithDuration:0.5f animations:^
     {
         CGRect viewFrame=_addAllocateViewContainer.frame;
         viewFrame.origin.y=0;
         _addAllocateViewContainer.frame=viewFrame;
     }completion:^(BOOL finished) {
         
         
     }];
    CGRect frame0=_resultTableView.frame;
    frame0.size.height=120 ;
    _resultTableView.frame=frame0;
   
    CGRect frame2=_lastView.frame;
    frame2.origin.y=345;
    _lastView.frame=frame2;
    

    _resultTextViewLabel.hidden=NO;
    _resultTextViewImage.hidden=NO;
    _resultTextView.text=@"";
    
    //if (_lastView.frame.size.height+_lastView.frame.origin.y>768) {
    
    
    [_resultScrollview setContentSize:CGSizeMake(0, _lastView.frame.origin.y+ _lastView.frame.size.height+50)];
    [_resultScrollview setScrollEnabled:YES];

    
    [allocateCodeArray removeAllObjects];
    [allocateNameArray removeAllObjects];
    [_resultHouseListTableView reloadData];
    _resultHouseListViewContainer.hidden=YES;
    
    
    CGRect frame=_resultHouseListViewContainer.frame;
    
    frame.size.height=1;
    [_resultHouseListViewContainer setFrame:frame];
    
    
    allocateIsOpen=NO;
    
    [guideCodeArray removeAllObjects];
    [guideNameArray removeAllObjects];
    [_resultGuideListTableView reloadData];
    _resultGuideListViewContainer.hidden=YES;
    
    CGRect framea=_resultGuideListViewContainer.frame;
    
    framea.size.height=1;
    [_resultGuideListViewContainer setFrame:framea];
    
    
    guideIsOpen=NO;
    

//    UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
//    [_resultGuideListArrowImage setImage:closeImage];
    
        CGRect frame1=_addAllocateResultView.frame;
        frame1.origin.y=0;
        [_addAllocateResultView setFrame:frame1];
    
}
-(void)requestAllocateList:(NSUInteger)pageIndex pageSize:(NSUInteger)pageSize
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        NSNumber *pageSizeNumber = [NSNumber numberWithInteger:pageSize];
        NSNumber *pageIndexNumber = [NSNumber numberWithInteger:pageIndex];
        //        NSString *pageSizeStr=[NSString stringWithFormat:@"%d",pageSize];
        //        NSString *pageIndexStr=[NSString stringWithFormat:@"%d",pageIndex];
        
        [params setObject:pageSizeNumber forKey:@"PageSize"];
        [params setObject:pageIndexNumber forKey:@"PageIndex"];
        [params setObject:_searchTextField.text forKey:@"KeyWord"];
        // NSLog(@"paramsLIST====%@",params);
        NSMutableArray *mDocumentLine=[NSMutableArray array];
        for (int i=0; i<filterTypeCodeArray.count; i++) {
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            
            [dic setValue:[filterTypeCodeArray objectAtIndex:i] forKey:@"FilterTypeCode"];
         
            [dic setValue:[selectFilterCodeArray objectAtIndex:i] forKey:@"FilterCode"];
            [mDocumentLine addObject:dic];
            
        }
        NSMutableArray *mDocumentLine1=[NSMutableArray array];
        for (int i=0; i<customTimeFilterTypeCodeArray.count; i++) {
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            [dic setValue:[customTimeFilterTypeCodeArray objectAtIndex:i] forKey:@"FilterTypeCode"];
            //  NSLog(@"countContentssss==%@",countContent);
            [dic setValue:startTimeStr forKey:@"Value1"];
            [dic setValue:endTimeStr forKey:@"Value2"];
            [mDocumentLine1 addObject:dic];
            
        }

        [params setObject:mDocumentLine forKey:@"DataLineFileterParam"];
        [params setObject:mDocumentLine1 forKey:@"DataLineFileterParam2"];
       
        [HttpRequest requestData:@"StoreManager/DTransList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
               
                    _productTotalCount=[[severDataDict.dataDict objectForKey:@"TotalCount"] integerValue];
                    _allocateTotalCount.text=[NSString stringWithFormat:@"有%lu条记录",(unsigned long)_productTotalCount];
                    
                    if (_productTotalCount%6!=0) {
                        _productTotalPage=_productTotalCount/6+1;
                    }
                    else if (_productTotalCount%6==0)
                    {
                        _productTotalPage=_productTotalCount/6;
                    }
                    
                  
                    NSMutableArray  *allocateListArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    //   int total=0;
                    if ( allocateListArray.count>0) {
                        for (int i=0; i< allocateListArray.count; i++) {
                            [allcateNumArray addObject:[[allocateListArray objectAtIndex:i] objectForKey:@"DocNum"]];
                          //  [allcatePriceArray addObject:[[allocateListArray objectAtIndex:i] objectForKey:@"GramTotal"]];
                            [allcateGuideNameArray addObject:[[allocateListArray objectAtIndex:i] objectForKey:@"UserName"]];
                            [allcateDateArray addObject:[[allocateListArray objectAtIndex:i] objectForKey:@"DocDate"]];
                            [allcateStatusArray addObject:[[allocateListArray objectAtIndex:i] objectForKey:@"WhsName"]];
                            [allcateDocStatusArray addObject:[[allocateListArray objectAtIndex:i] objectForKey:@"DocStatus"]];
                            [allcatePriceArray addObject:[[allocateListArray objectAtIndex:i] objectForKey:@"DocTotal"]];
                            [allcateProductNameArray addObject:[[allocateListArray objectAtIndex:i] objectForKey:@"ItemName"]];
                            [allcateWeightArray addObject:[[allocateListArray objectAtIndex:i] objectForKey:@"GramTotal"]];
                            [allcateNumberArray addObject:[[allocateListArray objectAtIndex:i] objectForKey:@"Number"]];
                        }
                    }
                  
                    [_allocateTableView reloadData];
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        [Global loginViewController:self noteStr:requestResultStr];
                        //   [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    if (_refreshHeaderView == nil) {
        
        EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - _allocateTableView.bounds.size.height, self.view.frame.size.width, _allocateTableView.bounds.size.height)];
        view.delegate = self;
        [_allocateTableView addSubview:view];
        _refreshHeaderView = view;
        
        
    }
    
    //  update the last update date
    [_refreshHeaderView refreshLastUpdatedDate];
    // Do any additional setup after loading the view from its nib.
}
#pragma mark -
#pragma mark Data Source Loading / Reloading Methods

- (void)reloadTableViewDataSource{
    [allcateNumArray removeAllObjects];
    [allcatePriceArray removeAllObjects];
    [allcateGuideNameArray removeAllObjects];
    [allcateDateArray removeAllObjects];
    [allcateStatusArray removeAllObjects];
    [allcateDocStatusArray removeAllObjects];
    [allcatePriceArray removeAllObjects];
    [allcateProductNameArray removeAllObjects];
    [allcateNumberArray removeAllObjects];
    [allcateWeightArray removeAllObjects];
    _productPageIndex=0;
    [self loadProductNextPage:_productPageIndex];
    //  should be calling your tableviews data source model to reload
    //  put here just for demo
    _reloading = YES;
    
}

- (void)doneLoadingTableViewData{
    
    //  model should call this when its done loading
    _reloading = NO;
    [_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:_allocateTableView];
    
}


#pragma mark -
#pragma mark UIScrollViewDelegate Methods

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
      if (scrollView==_allocateTableView) {
    [_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
      }
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
      if (scrollView==_allocateTableView) {
    [_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
      }
}


#pragma mark -
#pragma mark EGORefreshTableHeaderDelegate Methods

- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{
    
    [self reloadTableViewDataSource];
    [self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:3.0];
    
}

- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{
    
    return _reloading; // should return if data source model is reloading
    
}

- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{
    
    return [NSDate date]; // should return date data source was last changed
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
   
    if (tableView ==_allocateTableView) {
        return allcateNumArray.count;
    }
   
    else if (tableView==_resultTableView)
    {
        return selectedProductCodeArray.count;
    }
//    else if (tableView==_resultTableView)
//    {
//        return selectedProductCodeArray.count;
//    }
    
    else if (tableView==_resultGuideListTableView)
    {
        return guideCodeArray.count;
    }
    else if (tableView==_resultHouseListTableView)
    {
        return allocateCodeArray.count;
    }

    else if (tableView==_detailTableView)
    {
        return detailUrlArray.count;
    }

       return 1;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(tableView==_allocateTableView||tableView==_resultTableView||tableView==_detailTableView)
        return 120.0f;
    return 55;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView==_allocateTableView) {
        static NSString * identifier = @"Cell";
        AllocateLibraryTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"AllocateLibraryTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
            // cell.delegate=self;
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (allcateNumArray.count>0) {
            cell.numLabel.text=[NSString stringWithFormat:@"%@",[allcateNumArray objectAtIndex:indexPath.row]];
            [Global resizeForLable:cell.numLabel WithText:cell.numLabel.text parentView:self.view];
           // [self resizeLabel:cell.numLabel];
            
            CGRect frame=cell.statusTagLabel.frame;
            frame.origin.x=cell.numLabel.frame.origin.x+cell.numLabel.frame.size.width+8;
            cell.statusTagLabel.frame=frame;


            CGRect frame2=cell.statusLabel.frame;
            frame2.origin.x=cell.statusTagLabel.frame.origin.x+cell.statusTagLabel.frame.size.width+3;
            cell.statusLabel.frame=frame2;
            
            
        }
        if (allcateStatusArray.count>0) {
            cell.statusLabel.text=[NSString stringWithFormat:@"%@",[allcateStatusArray objectAtIndex:indexPath.row] ];
           // [self resizeLabel:cell.statusLabel];
            [Global resizeForLable:cell.statusLabel WithText:cell.statusLabel.text parentView:self.view];
            CGRect frame2=cell.docTypeLabel.frame;
            frame2.origin.x=cell.statusLabel.frame.origin.x+cell.statusLabel.frame.size.width+3;
            cell.docTypeLabel.frame=frame2;
//            if ([cell.statusLabel.text isEqualToString:@"上柜"]) {
//                [cell.statusLabel setBackgroundColor:[UIColor colorWithRed:199.0f/255.0f green:156.0f/255.0f blue:43.0f/255.0f alpha:1.0f]];
//            }
//            else
//            {
//                [cell.statusLabel setBackgroundColor:[UIColor colorWithRed:112.0f/255.0f green:177.0f/255.0f blue:36.0f/255.0f alpha:1.0f]];
//            }
        }
        
        if (allcateDocStatusArray.count>0) {
            NSString *str=[allcateDocStatusArray objectAtIndex:indexPath.row];
            
            // NSString *statusStr=[orderShipmentStatusArray objectAtIndex:indexPath.row];
            if (str.length>0) {
                cell.docTypeLabel.text=[NSString stringWithFormat:@"【%@】",str];
            }
            else
            {
                cell.docTypeLabel.text=@"";
            }
            
            if ([str isEqualToString:@"未到货"]) {
                [cell.docTypeLabel setTextColor:[Global parseStatusColor:str]];
            }
            else if ([str isEqualToString:@"在途"]) {
                [cell.docTypeLabel setTextColor:[Global parseStatusColor:str]];
            }
            else if ([str isEqualToString:@"部分到货"]) {
                [cell.docTypeLabel setTextColor:[Global parseStatusColor:str]];
            }
            
            else if ([str isEqualToString:@"已到货"]) {
                [cell.docTypeLabel setTextColor:[Global parseStatusColor:str]];
            }
            
            
        }
        if (allcatePriceArray.count>0) {
            float AvgPrice=[[allcatePriceArray objectAtIndex:indexPath.row] floatValue];
            NSString *AvgPriceStr=[Global floatConvertPercentile:AvgPrice];
            //  NSString *marketStr=[NSString stringWithFormat:@"¥%0.02f",[[inquiryPriceArray objectAtIndex:indexPath.row] floatValue]];
            cell.priceLabel.text=[NSString stringWithFormat:@"¥%@",AvgPriceStr];
           // cell.priceLabel.text=[NSString stringWithFormat:@"¥%0.02f",[[allcatePriceArray objectAtIndex:indexPath.row] floatValue]];
        }
        if (allcateDateArray.count>0) {
            cell.dateLabel.text=[allcateDateArray objectAtIndex:indexPath.row];
        }
        if (allcateGuideNameArray.count>0) {
            if ([allcateGuideNameArray objectAtIndex:indexPath.row]!=[NSNull null]) {
               NSString *guideNameStr=[allcateGuideNameArray objectAtIndex:indexPath.row];
            if (guideNameStr.length>0) {
                cell.guideNameLabel.text=guideNameStr;
            }
            }
            else
            {
                cell.guideNameLabel.text=@"未填写";
            }
             //   [self resizeLabel:cell.guideNameLabel];
            [Global resizeForLable:cell.guideNameLabel WithText:cell.guideNameLabel.text parentView:self.view];
            
            CGRect frame=cell.dateTagLabel.frame;
            frame.origin.x=cell.guideNameLabel.frame.origin.x+cell.guideNameLabel.frame.size.width+15;
            cell.dateTagLabel.frame=frame;
            
            CGRect frame1=cell.dateLabel.frame;
            frame1.origin.x=cell.dateTagLabel.frame.origin.x+cell.dateTagLabel.frame.size.width+3;
            cell.dateLabel.frame=frame1;
            
            
        }
        NSString *numberStr=@"";
        NSString *weightStr=@"";
        NSString *nameStr=@"";
        if (allcateNumberArray.count>0) {
            numberStr=[NSString stringWithFormat:@"%d",[[allcateNumberArray objectAtIndex:indexPath.row] integerValue]];
        }
        if (allcateWeightArray.count>0) {
            weightStr=[NSString stringWithFormat:@"%0.02f",[[allcateWeightArray objectAtIndex:indexPath.row] floatValue]];
        }

        if (allcateProductNameArray.count>0) {
           nameStr=[NSString stringWithFormat:@"%@",[allcateProductNameArray objectAtIndex:indexPath.row]];
            if ([numberStr floatValue]>1) {
                cell.productNameLabel.text=[NSString stringWithFormat:@"%@...  共%@件/%@g",nameStr,numberStr,weightStr];
            }
            else
            {
                cell.productNameLabel.text=[NSString stringWithFormat:@"%@  共%@件/%@g",nameStr,numberStr,weightStr];
            }

           // cell.productNameLabel.text=nameStr;//[shopCartMarketArray objectAtIndex:indexPath.row];
           // [self resizeLabel:cell.productNameLabel];
            [Global resizeForLable: cell.productNameLabel WithText: cell.productNameLabel.text parentView:self.view];
            
            CGRect frame=cell.priceTagLabel.frame;
            frame.origin.x=cell.productNameLabel.frame.origin.x+cell.productNameLabel.frame.size.width+17;
            cell.priceTagLabel.frame=frame;
            
            CGRect frame1=cell.priceLabel.frame;
            frame1.origin.x=cell.priceTagLabel.frame.origin.x+cell.priceTagLabel.frame.size.width+3;
            cell.priceLabel.frame=frame1;
            
        }
        
        
        if (indexPath.row == [allcateNumArray count] - 1)
        {
            if (_productPageIndex<=_productTotalPage) {
                //    NSLog(@"###LOADING???");
                [self loadProductNextPage:_productPageIndex];
            }
            
        }
        return cell;
    }
    else if (tableView==_resultTableView)
    {
        static NSString * const  ResultTableViewCellIdentifier = @"ResultTableViewCellIdentifier";
        UpCounterDetailTableViewCell *cell=( UpCounterDetailTableViewCell *)[tableView dequeueReusableCellWithIdentifier: ResultTableViewCellIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"UpCounterDetailTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.receiverLabel.hidden=YES;
         cell.receiverTagLabel.hidden=YES;
//        if (detailAttributesArray.count>0) {
//            if ([detailAttributesArray objectAtIndex:indexPath.row]!=[NSNull null]) {
//                cell.attributesLabel.text=[NSString stringWithFormat:@"%@",[detailAttributesArray objectAtIndex:indexPath.row]];
//                
//            }
          //  [self resizeLabel: cell.attributesLabel];
            
            CGRect frame= cell.weightTagLabel.frame;
//            if ([[detailAttributesArray objectAtIndex:indexPath.row] length]>0) {
//                
//                frame.origin.x=cell.attributesLabel.frame.origin.x+cell.attributesLabel.frame.size.width+12;
//            }
//            else
//            {
                frame.origin.x=96;
            //}
            cell.weightTagLabel.frame=frame;
            
            CGRect frame1= cell.resultProductWeightLabel.frame;
            frame1.origin.x=cell.weightTagLabel.frame.origin.x+cell.weightTagLabel.frame.size.width+1;
            cell.resultProductWeightLabel.frame=frame1;
            
       // }
        

        if (selectedProductImageArray.count>0) {
            if ([[selectedProductImageArray objectAtIndex:indexPath.row] length]>0) {
                
            
            [cell.resultProductImageView setImageWithURL:[NSURL URLWithString:[selectedProductImageArray objectAtIndex:indexPath.row]]];
            }
            else
            {
                [cell.resultProductImageView setImage:[UIImage imageNamed:@"zhanweitu_.png"]];
            }
        }
        if (selectedProductWeightArray.count>0) {
            cell.resultProductWeightLabel.text=[selectedProductWeightArray objectAtIndex:indexPath.row];
           // [self resizeLabel:cell.resultProductWeightLabel];
            [Global resizeForLable:cell.resultProductWeightLabel WithText:cell.resultProductWeightLabel.text parentView:self.view];
        }
        if (selectedProductWhereArray.count>0) {
            cell.storeAddressLabel.text=[selectedProductWhereArray objectAtIndex:indexPath.row];
        }
        if (selectedProductPriceArray.count>0) {
            cell.resultProductPriceLabel.text=[NSString stringWithFormat:@"¥%@",[selectedProductPriceArray objectAtIndex:indexPath.row]];
             [Global resizeForLable:cell.resultProductPriceLabel WithText:cell.resultProductPriceLabel.text parentView:self.view];
          //  [self resizeLabel:cell.resultProductPriceLabel];
            CGRect frame=cell.resultProductPriceLabel.frame;
            frame.origin.x=cell.resultProductWeightLabel.frame.origin.x+cell.resultProductWeightLabel.frame.size.width+15;
            cell.resultProductPriceLabel.frame=frame;
        }
        if (selectedProductNameArray.count>0) {
            cell.resultProductNameLabel.text=[NSString stringWithFormat:@"%@ %@",[selectedProductCodeArray objectAtIndex:indexPath.row],[selectedProductNameArray objectAtIndex:indexPath.row]];//[selectedProductNameArray objectAtIndex:indexPath.row];
        }
        cell.dotLineLabel.hidden=NO;
        if (indexPath.row==selectedProductCodeArray.count-1) {
            cell.dotLineLabel.hidden=YES;
        }
        
        return cell;
        
    }
    
    else if (tableView==_resultGuideListTableView)
    {
        static NSString * const  GuideListIdentifier = @"GuideListCellIdentifier";
        GuideListTableViewCell *cell=( GuideListTableViewCell *)[tableView dequeueReusableCellWithIdentifier: GuideListIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"GuideListTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (guideNameArray.count>0) {
            cell.guideNameLabel.text=[guideNameArray objectAtIndex:indexPath.row];
        }
        return cell;
        
    }
    else if (tableView==_resultHouseListTableView)
    {
        static NSString * const  HouseListIdentifier = @"HouseListIdentifier";
        GuideListTableViewCell *cell=( GuideListTableViewCell *)[tableView dequeueReusableCellWithIdentifier: HouseListIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"GuideListTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (allocateNameArray.count>0) {
            cell.guideNameLabel.text=[allocateNameArray objectAtIndex:indexPath.row];
        }
        return cell;
        
    }

    else if (tableView==_detailTableView)
    {
        static NSString * const  ChangeTableViewCellIdentifier = @"ChangeTableViewCellIdentifier";
        UpCounterDetailTableViewCell *cell=( UpCounterDetailTableViewCell *)[tableView dequeueReusableCellWithIdentifier: ChangeTableViewCellIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"UpCounterDetailTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.receiverTagLabel.hidden=YES;
        cell.receiverLabel.hidden=YES;
        if (detailUrlArray.count>0) {
            if ([[detailUrlArray objectAtIndex:indexPath.row] length]>0) {
 
            [cell.resultProductImageView setImageWithURL:[NSURL URLWithString:[detailUrlArray objectAtIndex:indexPath.row]]];
            }
            else
            {
                [cell.resultProductImageView setImage:[UIImage imageNamed:@"zhanweitu_.png"]];
            }
        }
        if (detailWeightArray.count>0) {
            cell.resultProductWeightLabel.text=[NSString stringWithFormat:@"%0.02fg",[[detailWeightArray objectAtIndex:indexPath.row] floatValue]];
             [Global resizeForLable:cell.resultProductWeightLabel WithText:cell.resultProductWeightLabel.text parentView:self.view];
           // [self resizeLabel:cell.resultProductWeightLabel];
        }
        if (detailAttributesArray.count>0) {
            if ([detailAttributesArray objectAtIndex:indexPath.row]!=[NSNull null]) {
                cell.attributesLabel.text=[NSString stringWithFormat:@"%@",[detailAttributesArray objectAtIndex:indexPath.row]];
                
            }
          //  [self resizeLabel: cell.attributesLabel];
            [Global resizeForLable:cell.attributesLabel WithText:cell.attributesLabel.text parentView:self.view];
            
            CGRect frame= cell.weightTagLabel.frame;
            if ([[detailAttributesArray objectAtIndex:indexPath.row] length]>0) {
                
                frame.origin.x=cell.attributesLabel.frame.origin.x+cell.attributesLabel.frame.size.width+12;
            }
            else
            {
                frame.origin.x=cell.attributesLabel.frame.origin.x+cell.attributesLabel.frame.size.width;
            }
            cell.weightTagLabel.frame=frame;
            
            CGRect frame1= cell.resultProductWeightLabel.frame;
            frame1.origin.x=cell.weightTagLabel.frame.origin.x+cell.weightTagLabel.frame.size.width+1;
            cell.resultProductWeightLabel.frame=frame1;
            
        }
        

        if (detailAddressArray.count>0) {
            cell.storeAddressLabel.text=[detailAddressArray objectAtIndex:indexPath.row];
        }
        if (detailLinePriceArray.count>0) {
            cell.resultProductPriceLabel.text=[NSString stringWithFormat:@"¥%0.02f",[[detailLinePriceArray objectAtIndex:indexPath.row] floatValue]];
            CGRect frame=cell.resultProductPriceLabel.frame;
            frame.origin.x=cell.resultProductWeightLabel.frame.origin.x+cell.resultProductWeightLabel.frame.size.width+12;
            cell.resultProductPriceLabel.frame=frame;
        }
        if (detailProductNameArray.count>0) {
            cell.resultProductNameLabel.text=[NSString stringWithFormat:@"%@ %@",[detailProductCodeArray objectAtIndex:indexPath.row],[detailProductNameArray objectAtIndex:indexPath.row]];//[detailProductNameArray objectAtIndex:indexPath.row];
        }
        cell.dotLineLabel.hidden=NO;
        if (indexPath.row==detailUrlArray.count-1) {
            cell.dotLineLabel.hidden=YES;
        }
        return cell;
        
    }
    

    return nil;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView==_resultTableView) {
        return YES;
    }
    return NO;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView==_resultTableView) {
        if (editingStyle == UITableViewCellEditingStyleDelete) {
            
            [selectedProductImageArray removeObjectAtIndex:indexPath.row];
            [selectedProductWeightArray removeObjectAtIndex:indexPath.row];
            [selectedProductPriceArray removeObjectAtIndex:indexPath.row];
            [selectedProductNameArray removeObjectAtIndex:indexPath.row];
            [selectedProductCodeArray removeObjectAtIndex:indexPath.row];
            [selectedProductWhereArray removeObjectAtIndex:indexPath.row];
            
           // [tableView reloadData];
            [_resultTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
            
            float total=0.0f;
            for (int i=0; i<selectedProductWeightArray.count; i++) {
                total=total+[[selectedProductWeightArray objectAtIndex:i] floatValue];
            }
            
            _totalMoneyLabel.text=[NSString stringWithFormat:@"共%lu件,%0.02fg",(unsigned long)selectedProductWeightArray.count,total];
            
            CGRect frame1=_resultTableView.frame;
            frame1.size.height=120*selectedProductCodeArray.count;
            _resultTableView.frame=frame1;
            
            
            CGRect frame2=_lastView.frame;
            frame2.origin.y=_resultTableView.frame.origin.y+_resultTableView.frame.size.height;
            _lastView.frame=frame2;
//            if (_lastView.frame.size.height+_lastView.frame.origin.y>710) {
//                
//                CGRect frame3=_confirmAllocateBtn.frame;
//                frame3.origin.y=_lastView.frame.origin.y+_lastView.frame.size.height+20;
//                _confirmAllocateBtn.frame=frame3;
//               
//            }
//            else
//            {
//                CGRect frame3=_confirmAllocateBtn.frame;
//                frame3.origin.y=718;
//                _confirmAllocateBtn.frame=frame3;
//            }
            [_resultScrollview setContentSize:CGSizeMake(0, _lastView.frame.origin.y+ _lastView.frame.size.height+50)];
            [_resultScrollview setScrollEnabled:YES];
            //        else if (editingStyle == UITableViewCellEditingStyleInsert) {
            //            // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
            //        }
            
        }
    }
}
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
    return @"删除";
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
        if (tableView==_resultGuideListTableView) {
       // if ([guideOrAllocateStr isEqualToString:@"GUIDE"]) {
       
        guideCodeStr=[guideCodeArray objectAtIndex:indexPath.row];
        
        _resultGuideListViewContainer.hidden=YES;
        [UIView animateWithDuration:0.5 animations:^{
            
//            UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
//            [_resultGuideListArrowImage setImage:closeImage];
            CGRect frame=_resultGuideListViewContainer.frame;
            
            frame.size.height=1;
            [_resultGuideListViewContainer setFrame:frame];
            
        } completion:^(BOOL finished){
            guideIsOpen=NO;
        }];
        _resultGuideNameLabel.text=[guideNameArray objectAtIndex:indexPath.row];
   // }
    }
else if (tableView==_detailTableView)
{
    _isLoad=@"Y";
    if (commonProductDetailVC.view!=nil) {
        
        [commonProductDetailVC removeFromParentViewController];
        [commonProductDetailVC.view removeFromSuperview];
        
    }
    commonProductDetailVC=[[CommonProductDetailViewController alloc] init];
    commonProductDetailVC.delegate=self;
    commonProductDetailVC.codeStr=[detailProductCodeArray objectAtIndex:indexPath.row];
    commonProductDetailVC.view.frame = CGRectMake(0,
                                                  0,
                                                  self.view.bounds.size.width,
                                                  self.view.bounds.size.height);
    
    [self addChildViewController:commonProductDetailVC];
    [self.view addSubview:commonProductDetailVC.view];
}
 else if (tableView==_resultHouseListTableView) {
   //  if ([guideOrAllocateStr isEqualToString:@"ALLOCATE"])
   // {
       // NSLog(@"eeeeee");
        allocateCodeStr=[allocateCodeArray objectAtIndex:indexPath.row];
        
        _resultHouseListViewContainer.hidden=YES;
        [UIView animateWithDuration:0.5 animations:^{
            
            CGRect frame=_resultHouseListViewContainer.frame;
            
            frame.size.height=1;
            [_resultHouseListViewContainer setFrame:frame];
            
        } completion:^(BOOL finished){
            allocateIsOpen=NO;
        }];
    _resultAllocateNameLabel.text=[allocateNameArray objectAtIndex:indexPath.row];
     [Global resizeForLable:_resultAllocateNameLabel WithText:_resultAllocateNameLabel.text parentView:self.view];
     CGRect frameK=_resultAllocateNameLabel.frame;
     frameK.origin.x=_resultAllocateListArrowImage.frame.origin.x-frameK.size.width-5;
     _resultAllocateNameLabel.frame=frameK;
  //  }
 }
     else if (tableView==_allocateTableView)
     {
         [_searchTextField resignFirstResponder];
         [detailUrlArray removeAllObjects];
         [detailProductNameArray removeAllObjects];
         [detailProductCodeArray removeAllObjects];
         [detailLinePriceArray removeAllObjects];
         [detailWeightArray removeAllObjects];
         [detailAttributesArray removeAllObjects];
         [detailAddressArray removeAllObjects];
         
         [self requestDetail:[allcateNumArray objectAtIndex:indexPath.row]];
         [UIView animateWithDuration:0.5 animations:^{
             
             
             CGRect frame=_addAllocateDetailViewContainer.frame;
             
             frame.origin.y=0;
             [_addAllocateDetailViewContainer setFrame:frame];
             
         } completion:^(BOOL finished){
             
         }];
         
     }

    
}
-(void)commonProductDetailShopCartClick
{
    if ([self.delegate respondsToSelector:@selector(AllocateLibraryShopCtarClick)]) {
        
        [self.delegate AllocateLibraryShopCtarClick];
    }

}
-(void)requestDetail:(NSString *)codeStr
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:codeStr forKey:@"DocNum"];
        [HttpRequest requestData:@"StoreManager/GetTrans" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                     //   NSLog(@"222=%@",severDataDict.dataDict);
                    _detailNumLabel.text=[severDataDict.dataDict objectForKey:@"DocNum"];
               //     [self resizeLabel:_detailNumLabel];
                    [Global resizeForLable:_detailNumLabel WithText:_detailNumLabel.text parentView:self.view];
                    NSString *statusStr=[severDataDict.dataDict objectForKey:@"DocStatus"];
                    if (statusStr.length>0) {
                        _detailStatusLabel.text=[NSString stringWithFormat:@"【%@】",statusStr];
                    }
                    else
                    {
                        _detailStatusLabel.text=@"";
                    }
                    
                    if ([statusStr isEqualToString:@"未到货"]) {
                        [_detailStatusLabel setTextColor:[Global parseStatusColor:statusStr]];
                    }
                    else if ([statusStr isEqualToString:@"在途"]) {
                        [_detailStatusLabel setTextColor:[Global parseStatusColor:statusStr]];
                    }
                    else if ([statusStr isEqualToString:@"部分到货"]) {
                        [_detailStatusLabel setTextColor:[Global parseStatusColor:statusStr]];
                    }
                    
                    else if ([statusStr isEqualToString:@"已到货"]) {
                        [_detailStatusLabel setTextColor:[Global parseStatusColor:statusStr]];
                    }
                    CGRect framea=_detailStatusLabel.frame;
                    framea.origin.x=_detailNumLabel.frame.origin.x+_detailNumLabel.frame.size.width;
                    _detailStatusLabel.frame=framea;

                    _detailGuideNameLabel.text=[severDataDict.dataDict objectForKey:@"UserName"];
                    _detailTextView.text=[severDataDict.dataDict objectForKey:@"Remark"];
                   // [Global resizeTextView:_detailTextView contentStr: _detailTextView.text];
                    CGFloat height=  [Global heightForTextView:_detailTextView WithText:_detailTextView.text];
                    
                    CGRect frameA=_detailTextView.frame;
                    frameA.size.height=height;
                    _detailTextView.frame=frameA;
                    
                    CGRect frameD=_detailLastView.frame;
                    frameD.size.height=_detailTextView.frame.origin.y+_detailTextView.frame.size.height+10;
                    _detailLastView.frame=frameD;
                    
                    _detailAddressLabel.text=[severDataDict.dataDict objectForKey:@"WhsName"];
                  //  [self resizeLabel:_detailAddressLabel];
                     [Global resizeForLable:_detailAddressLabel WithText:_detailAddressLabel.text parentView:self.view];
                    
                    CGRect frame=_detailGuideTagLabel.frame;
                    frame.origin.x=_detailAddressLabel.frame.origin.x+_detailAddressLabel.frame.size.width+10;
                    _detailGuideTagLabel.frame=frame;
                    
                    CGRect frame3=_detailGuideNameLabel.frame;
                    frame3.origin.x=_detailGuideTagLabel.frame.origin.x+_detailGuideTagLabel.frame.size.width+3;
                    _detailGuideNameLabel.frame=frame3;

                    
                    _detailDateNameLabel.text=[severDataDict.dataDict objectForKey:@"DocDate"];
                    _detailTotalLabel.text=[NSString stringWithFormat:@"(共%d件,%0.02fg)",[[severDataDict.dataDict objectForKey:@"Number"] integerValue],[[severDataDict.dataDict objectForKey:@"GramTotal"] floatValue]];
                    NSMutableArray *returnDataLineArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    float returnMonney=0;
                    for (int i=0; i<returnDataLineArray.count; i++) {
                        [detailUrlArray addObject:[[returnDataLineArray objectAtIndex:i] objectForKey:@"ImageUrl"]];
                        [detailProductNameArray addObject:[[returnDataLineArray objectAtIndex:i] objectForKey:@"ItemName"]];
                         [detailProductCodeArray addObject:[[returnDataLineArray objectAtIndex:i] objectForKey:@"ItemCode"]];
                        NSString *lineTotalStr=[NSString stringWithFormat:@"%0.02f",[[[returnDataLineArray objectAtIndex:i] objectForKey:@"LineTotal"] floatValue]];
                        [detailLinePriceArray addObject:[[returnDataLineArray objectAtIndex:i] objectForKey:@"Price"]];
                        returnMonney=returnMonney+[lineTotalStr floatValue];
                      //  NSString *weightStr=[NSString stringWithFormat:@"%d",[[[returnDataLineArray objectAtIndex:i] objectForKey:@"Gram"] floatValue]];
                        [detailWeightArray addObject:[[returnDataLineArray objectAtIndex:i] objectForKey:@"Gram"]];
                        [detailAttributesArray addObject:[[returnDataLineArray objectAtIndex:i] objectForKey:@"Attributes"]];
                        [detailAddressArray addObject:[[returnDataLineArray objectAtIndex:i] objectForKey:@"WhsFromName"]];
                        
                    }
                    
                    [_detailTableView reloadData];
                    
                    CGRect frame1=_detailTableView.frame;
                    frame1.size.height=120*detailUrlArray.count;
                    _detailTableView.frame=frame1;
                    
                    CGRect frame2=_detailLastView.frame;
                    frame2.origin.y=_detailTableView.frame.origin.y+_detailTableView.frame.size.height+10;
                    _detailLastView.frame=frame2;
                    
                    
                    
                    [_detailScrollview setContentSize:CGSizeMake(0, _detailLastView.frame.origin.y+ _detailLastView.frame.size.height)];
                    [_detailScrollview setScrollEnabled:YES];
                    
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if(textField==_resultTextField)
    {
        [self findProductList:_resultTextField.text];
        _resultTextField.text=@"";

    }
    if (textField==_searchTextField) {
        [allcateNumArray removeAllObjects];
        [allcatePriceArray removeAllObjects];
        [allcateGuideNameArray removeAllObjects];
        [allcateDateArray removeAllObjects];
        [allcateStatusArray removeAllObjects];
        [allcateDocStatusArray removeAllObjects];
        [allcatePriceArray removeAllObjects];
        [allcateProductNameArray removeAllObjects];
        [allcateNumberArray removeAllObjects];
        [allcateWeightArray removeAllObjects];
        _productPageIndex=0;
        [self loadProductNextPage:_productPageIndex];
        [_searchTextField resignFirstResponder];
    }

    return YES;
}
-(void)findProductList:(NSString *)codeStr
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:codeStr forKey:@"KeyWord"];
        NSNumber *pageSizeNumber = [NSNumber numberWithInteger:1];
        NSNumber *pageIndexNumber = [NSNumber numberWithInteger:1];
        [params setObject:pageSizeNumber forKey:@"PageSize"];
        [params setObject:pageIndexNumber forKey:@"PageIndex"];
        [params setObject:@"Trans" forKey:@"BType"];
        
        [HttpRequest requestData:@"Product/GetPItemList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    _resultNoteView.hidden=YES;
                    NSMutableArray *dataLineArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    if (![selectedProductCodeArray containsObject:codeStr]) {
                        for (int i=0; i< dataLineArray.count; i++) {
                            [selectedProductCodeArray addObject:[[dataLineArray objectAtIndex:i] objectForKey:@"ItemCode"]];
                            
                            NSString *urlStr=[[dataLineArray objectAtIndex:i] objectForKey:@"ImageUrl"];
                            [selectedProductImageArray addObject:urlStr];
                            [selectedProductWeightArray addObject:[NSString stringWithFormat:@"%0.02fg",[[[dataLineArray objectAtIndex:i] objectForKey:@"Gram"] floatValue]]];
                            [selectedProductPriceArray addObject:[NSString stringWithFormat:@"%0.02f",[[[dataLineArray objectAtIndex:i] objectForKey:@"Price"] floatValue]]];
                            [selectedProductNameArray addObject:[[dataLineArray objectAtIndex:i] objectForKey:@"ItemName"]];
                            [selectedProductWhereArray addObject:[[dataLineArray objectAtIndex:i] objectForKey:@"WhsName"]];
                        }
                    }
                    [_resultTableView  reloadData];
                    CGRect frame1=_resultTableView.frame;
                    frame1.size.height=120*selectedProductCodeArray.count;
                    _resultTableView.frame=frame1;
                    
                    
                    
                    float total=0.0f;
                    for (int i=0; i<selectedProductWeightArray.count; i++) {
                        total=total+[[selectedProductWeightArray objectAtIndex:i] floatValue];
                    }
                    _totalMoneyLabel.text=[NSString stringWithFormat:@"共%lu件,%0.02fg",(unsigned long)selectedProductWeightArray.count,total];
                  //  _lastTotalLabel.text=[NSString stringWithFormat:@"共%d件,%0.02fg",selectedProductWeightArray.count,total];
                    
                    CGRect frame2=_lastView.frame;
                    frame2.origin.y=_resultTableView.frame.origin.y+_resultTableView.frame.size.height;
                    _lastView.frame=frame2;
                    
                    [_resultScrollview setContentSize:CGSizeMake(0, _lastView.frame.origin.y+ _lastView.frame.size.height+50)];
                    [_resultScrollview setScrollEnabled:YES];

                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
}
-(IBAction)confirmAllocateBtnClick:(id)sender
{
    if (guideCodeStr.length>0) {
        
        
        if ([Global getLoginToken].length>0) {
            [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
            NSMutableArray *mDocumentLine=[NSMutableArray array];
            
            //        NSLog(@"findSkuAllCountArray===%@",findSkuAllCountArray);
            for (int i=0; i<selectedProductCodeArray.count; i++) {
                
                NSString *codeStr =[selectedProductCodeArray objectAtIndex:i];
                NSMutableDictionary *dic = [NSMutableDictionary dictionary];
                //    NSLog(@"codeContentssss==%@",codeContent);
                [dic setValue:codeStr forKey:@"ItemCode"];
                [mDocumentLine addObject:dic];
            }
            NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
            [params setObject:[Global getLoginToken] forKey:@"Token"];
            [params setObject:guideCodeStr forKey:@"GuideCode"];
             [params setObject:allocateCodeStr forKey:@"WhsCode"];
            [params setObject:_resultTextView.text forKey:@"Remark"];
         //   [params setObject:@"U" forKey:@"DocType"];
            
            [params setObject:mDocumentLine forKey:@"DataLine"];
            
         //    NSLog(@"aaaaaaaaaa===%@",params);
            [HttpRequest requestData:@"StoreManager/AddTrans" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                // [Global hideProgressHUDInternal:self.view];
                if (isSuccess) {
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        [Global showTextHudSub:requestResultStr view:self.view];
                 
                      
                        allocateCodeStr=@"";
                        guideCodeStr=@"";
                        
                       // UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
                    //    [_resultGuideListArrowImage setImage:closeImage];
                        _resultGuideNameLabel.text=@"";
                        
                        CGRect viewFrame1=_addAllocateViewContainer.frame;
                        viewFrame1.origin.y=768;
                        _addAllocateViewContainer.frame=viewFrame1;
                       
                        
                        [selectedProductImageArray removeAllObjects];
                        
                        [selectedProductWeightArray removeAllObjects];
                        [selectedProductPriceArray removeAllObjects];
                        [selectedProductNameArray removeAllObjects];
                        [selectedProductWhereArray removeAllObjects];
                        [selectedProductCodeArray removeAllObjects];
                        [_resultTableView reloadData];
                        
                        _totalMoneyLabel.text=[NSString stringWithFormat:@"共0件,0.00g"];
                        _resultGuideNameLabel.text=@"";
                        guideCodeStr=@"";
                        _resultAllocateNameLabel.text=@"";
                        allocateCodeStr=@"";
                        
                        [allcateNumArray removeAllObjects];
                        [allcatePriceArray removeAllObjects];
                        [allcateGuideNameArray removeAllObjects];
                        [allcateDateArray removeAllObjects];
                        [allcateStatusArray removeAllObjects];
                        [allcateDocStatusArray removeAllObjects];
                        [allcatePriceArray removeAllObjects];
                        [allcateProductNameArray removeAllObjects];
                        [allcateNumberArray removeAllObjects];
                        [allcateWeightArray removeAllObjects];
                        _productPageIndex=0;
                        [self loadProductNextPage:_productPageIndex];
                    }
                    else
                    {
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        //  [Global showTextHud:requestResultStr view:self.view];
                        [Global showTextHudSub:requestResultStr view:self.view];
                    }
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    [Global showTextHudSub:@"连接失败" view:self.view];
                }
            }];
            
        }
    }
    else
    {
        
        
        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请选择导购" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alert show];
        
        
    }
}

- (void)textViewDidChange:(UITextView *)textView
{
    if (textView==_resultTextView) {
        if (textView.text.length == 0) {
            _resultTextViewImage.hidden=NO;
            _resultTextViewLabel.hidden=NO;
        }
        else
        {
            _resultTextViewImage.hidden=YES;
            _resultTextViewLabel.hidden=YES;
            
        }
        
    }
    
}
//- (void)textClick
//{
//    
//    [_searchProductTextField becomeFirstResponder];
//}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    
   if (textField==_resultTextField)
    {
       // [self performSelector:@selector(textClick) withObject:nil afterDelay:0.1];
        
             CGRect viewFrame=_addAllocateViewContainer.frame;
             viewFrame.origin.y=0;
             _addAllocateViewContainer.frame=viewFrame;
        
//        UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
//        [_resultGuideListArrowImage setImage:closeImage];

        
    }
    return YES;
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
    if (textView==_resultTextView) {
        if ((_lastView.frame.origin.y+_lastView.frame.size.height+_resultScrollview.contentOffset.y+352>768)) {
            
            
            [UIView animateWithDuration:0.3 animations:^{
                CGRect viewFrame=_addAllocateResultView.frame;
                viewFrame.origin.y=-(_lastView.frame.origin.y+_lastView.frame.size.height-_resultScrollview.contentOffset.y+355-768);
                _addAllocateResultView.frame=viewFrame;
            } completion:^(BOOL finished){
                
            }];
        }

        
    }
    
    
    return YES;
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
    [_resultScrollview setContentOffset:CGPointMake(0, 0)];
    if (textView==_resultTextView) {
        [UIView animateWithDuration:0.3 animations:^{
            CGRect viewFrame=_addAllocateResultView.frame;
            viewFrame.origin.y=0;
            _addAllocateResultView.frame=viewFrame;
        } completion:^(BOOL finished){
            
        }];
        
    }
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
